let phone
function getCode(){
    let str = $('#mobile').val().trim();
    if (str) {
        var myreg = /^1([3456789])\d{9}$/;
        if (!myreg.test(str)) {
            alert('手机号格式不正确');
        } else {
            phone =str
            var codeDiv = document.querySelector('.model1');
            var copyBtn = document.querySelectorAll('.copyBtn');
            if (codeDiv.style.display !== 'none') {
                codeDiv.style.display = 'none';
            } else {
                codeDiv.style.display = 'block';
            }
            let phoneNumEnc = window.btoa(str);
            phone =phoneNumEnc
            $.ajax({
                type: 'GET',
                url: httpUrl+'/api/v1/open/searchPromoterCode?phoneNumEnc='+phoneNumEnc,
                success: function(result) {
                    if(result.code=='10000'){
                        var code = document.getElementById("code")
                        code.innerText=result.data.promoterCode
                        copyBtn.forEach(function(button) {
                            button.style.display = 'block';
                        });
                    }else{
                        setTimeout(()=>{
                            alert(result.msg)
                        },50)
                    }
                    codeDiv.style.display = 'none';

                },
                error: function(xhr, status, error) {
                    codeDiv.style.display = 'none';
                    setTimeout(()=>{
                        alert('查询失败，请稍后再试。');
                    },50)

                }
            });
        }
    } else {
        alert('请先输入手机号');
    }
}
function copy(){
    var content = document.getElementById("code").innerText;
    if(content){
        var textarea = document.createElement("textarea");
        textarea.value = content;
        document.body.appendChild(textarea);
        textarea.select();
        textarea.setSelectionRange(0, 99999);
        try {
            var successful = document.execCommand('copy');
            if (successful) {
                var codeDiv = document.querySelector('.model2');
                codeDiv.style.display = 'block';
                setTimeout(function() {
                    codeDiv.style.display = "none";
                }, 1500);
            }
        } catch (err) {
            alert('复制失败,请稍后再试！');
        }
        document.body.removeChild(textarea);
    }

}
function copyLink(){
    var content = document.getElementById("code").innerText;
    if(content){
        var textarea = document.createElement("textarea");
        textarea.value = 'https://y.uffiedo.cn?c='+content;
        document.body.appendChild(textarea);
        textarea.select();
        textarea.setSelectionRange(0, 99999);
        try {
            var successful = document.execCommand('copy');
            if (successful) {
                var codeDiv = document.querySelector('.model2');
                codeDiv.style.display = 'block';
                setTimeout(function() {
                    codeDiv.style.display = "none";
                }, 1500);
            }
        } catch (err) {
            alert('复制失败,请稍后再试！');
        }
        document.body.removeChild(textarea);
    }

}
function toSee() {
    let str = $('#mobile').val().trim();
    if (str) {
        var myreg = /^1([3456789])\d{9}$/;
        if (!myreg.test(str)) {
            alert('手机号格式不正确');
        } else {
            let phoneNumEnc = window.btoa(str);
            $.ajax({
                type: 'GET',
                url: httpUrl+'/api/v1/open/searchPromoterCode?phoneNumEnc='+phoneNumEnc,
                success: function(result) {
                    if(result.code=='10000'){
                        localStorage.setItem('userData', JSON.stringify(result.data));
                        window.location.href = 'withdraw.html';
                    }
                },
                error: function(xhr, status, error) {
                }
            });
        }
    } else {
        alert('请先输入手机号');
    }
}
